package com.yycx.module.weixin.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.base.service.impl.BaseServiceImpl;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.mybatis.query.CriteriaSave;
import com.yycx.module.weixin.client.entity.SysWechatTemplate;
import com.yycx.module.weixin.provider.mapper.SysWechatTemplateMapper;
import com.yycx.module.weixin.provider.service.SysWechatTemplateService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 公众号模板消息表接口实现类
 *
 * @author flyme
 * @date 2022-06-07
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysWechatTemplateServiceImpl extends BaseServiceImpl<SysWechatTemplateMapper, SysWechatTemplate> implements SysWechatTemplateService {

    @Override
    public ResultBody beforeAdd(CriteriaSave cs, SysWechatTemplate bwt, EntityMap extra) {
        return ResultBody.ok();
    }


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<SysWechatTemplate> cq, SysWechatTemplate bwt, EntityMap requestMap) {
        cq.orderByDesc("bwt.createTime");
        return ResultBody.ok();
    }

    @Override
    public SysWechatTemplate findByWeChatAndCode(Long weChatId, String templateCode) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("weChatId", weChatId);
        qw.eq("templateCode", templateCode);
        return getOne(qw);
    }
}
